/**
 * @description 商品列表增删改查 api 路由
 * @author LI
 */

const router = require('koa-router')()
const {
  getDecoratitemInfosAll,
  addDecoratitemInfo,
  updateDecoratitemInfo,
  deleteDecoratitemInfo
} = require('../../controller/decoratitemInfo')

router.prefix('/jihuide/decoratitemInfo')

// 添加商品项目信息
router.post('/addDecoratitemInfo', async (ctx, next) => {
  let { goodsInfoId, decoratItemId, itemNumber, itemPrice } = ctx.request.body
  goodsInfoId = parseInt(goodsInfoId)
  decoratItemId = parseInt(decoratItemId)
  itemNumber = parseInt(itemNumber)
  itemPrice = Number(itemPrice)
  // 接下来交给控制层
  ctx.body = await addDecoratitemInfo({
    goodsInfoId,
    decoratItemId,
    itemNumber,
    itemPrice,
  })
})

// 查询所有项目信息
router.post('/getDecoratitemInfosAll', async (ctx, next) => {
  let { goodsInfoId, page, limit } = ctx.request.body
  goodsInfoId = parseInt(goodsInfoId)
  // 接下来交给控制层
  ctx.body = await getDecoratitemInfosAll({
    goodsInfoId,
    page,
    limit,
  })
})

// 修改商品项目信息
router.post('/updateDecoratitemInfo', async (ctx, next) => {
  let { id, itemNumber, itemPrice } = ctx.request.body
  id = parseInt(id)
  itemNumber = parseInt(itemNumber)
  itemPrice = Number(itemPrice)
  // 接下来交给控制层
  ctx.body = await updateDecoratitemInfo({
    id,
    itemNumber,
    itemPrice,
  })
})

// 删除商品信息
router.post('/deleteDecoratitemInfo', async (ctx, next) => {
  let { id } = ctx.request.body
  id = parseInt(id)
  // 接下来交给控制层
  ctx.body = await deleteDecoratitemInfo(id)
})

module.exports = router
